import { allPages, menuPages } from '@/views/Pages/index.js'

// 手动配置的嵌套路由
const customMenus = [
  {
    path: '/user',
    meta: { title: '用户/角色', icon: 'el-icon-user' },
    children: [
      {
        path: '/userList',
        name: 'userList',
        meta: { title: '用户列表' },
        component: () => import('@/views/Pages/userList.vue'),
      },
      {
        path: '/roleList',
        name: 'roleList',
        meta: { title: '角色列表' },
        component: () => import('@/views/Pages/roleList.vue'),
      },
    ],
  },
]

export const menuRoutes = [
  ...allPages,
  ...customMenus.flatMap((menu) => menu.children || []),
]

// 只显示 showInMenu !== false 的
export const visibleMenus = [
  ...menuPages,
  ...customMenus
    .map((menu) => {
      if (menu.children) {
        return {
          ...menu,
          children: menu.children.filter(
            (child) => child.meta?.showInMenu !== false
          ),
        }
      }
      return menu.meta?.showInMenu !== false ? menu : null
    })
    .filter(Boolean),
]
export default visibleMenus
